<?php

namespace app\index\dao;

use app\common\model\ConsultingRedPacket;
use ShidianUtil\Thinkphp\Dao\DaoTrait;

/**
 * ConsultingRedPacketDao 数据访问对象
 * Class ConsultingRedPacketDao
 * @package app\dao
 * @method ConsultingRedPacket findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method ConsultingRedPacket insertActive(array $params, array $allow_field = [])
 * @method ConsultingRedPacket updateActive(ConsultingRedPacket $model, array $params, array $allow_field = [])
 * @method ConsultingRedPacket findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method ConsultingRedPacket updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(ConsultingRedPacket $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class ConsultingRedPacketDao
{
    use DaoTrait;

    /**
     * @var ConsultingRedPacket
     */
    private $baseModel;

    /**
     * ConsultingRedPacketDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = ConsultingRedPacket::class;
    }

    public function select($version, $page, $page_size)
    {
        return ConsultingRedPacket::order('ord', 'ASC')
            ->where('version', $version)
            ->withAttr([
                'price' => function ($value) {
                    return number_format($value, 1, '.', '');
                }
            ])
            ->append(['iconImg'])
            ->select();
    }
}
